//
//  SleepDataModels.swift
//  TimeBoat
//
//  Created by bo wang on 2022/8/30.
//  Copyright © 2022 Time Boat. All rights reserved.
//

import Foundation
import YYModel

@objc class SleepDataUnit: ChartsDataUnit {
    @objc var totalDeepSleepMinute: Double = 0
    @objc var totalLightSleepMinute: Double = 0
    @objc var totalMinute: Double = 0
    @objc var totalSoberMinute: Double = 0
}

@objc class SleepDailyDataUnit: NSObject {
    @objc var duration: Double = 0
    @objc var sleepState: Int = 0
    @objc var time: String?
    
    var start: Double? {
        guard let time = time else { return nil }
        let cmps = time.split(separator: ":")
        guard let hour = safe_int_or_nil(cmps.first),
              let minute = safe_int_or_nil(cmps.last) else { return nil }
        let decimalTime = Double(hour) + Double(minute / 60)
        // 12点之后0点之前的时间定义为负数，比如23:00为 -1.0   22:30 为 -1.5
        if decimalTime > 12 {
            return decimalTime - 24
        }
        return decimalTime
    }
    
    var end: Double? {
        guard let start = start else { return nil }
        return start + duration / 60
    }
}

@objc class SleepYearlyDataUnit: ChartsYearDataUnit {
    @objc var averageDeepSleepMinute: Double = 0
    @objc var averageLightSleepMinute: Double = 0
    @objc var averageSoberMinute: Double = 0
    @objc var dataCount: Int = 0
    @objc var totalDeepSleepMinute: Double = 0
    @objc var totalLightSleepMinute: Double = 0
    @objc var totalMinute: Double = 0
    @objc var totalSoberMinute: Double = 0
}

@objc class SleepNormalDataModel: ChartsDataModel {
    @objc var list: [SleepDataUnit] = []
    @objc static func modelContainerPropertyGenericClass() -> [String: Any]? {[
        "list": SleepDataUnit.self
    ]}
}

@objc class SleepDailyDataModel: ChartsDataModel {
    @objc var list: [SleepDailyDataUnit] = []
    @objc static func modelContainerPropertyGenericClass() -> [String: Any]? {[
        "list": SleepDailyDataUnit.self
    ]}
}

@objc class SleepYearlyDataModel: ChartsDataModel {
    @objc var list: [SleepYearlyDataUnit] = []
    @objc static func modelContainerPropertyGenericClass() -> [String: Any]? {[
        "list": SleepYearlyDataUnit.self
    ]}
}
